package newcoder.t6;

//[1,-2,3,10,-4,7,2,-5]
//1,2,-1,-2,2,1,-2,1,4,-5,4
public class Solution {

    public static void main(String[] args) {
//        int[] a = {1,-2,3,10,-4,7,2,-5};
        int[] a = {1,2,-1,-2,2,1,-2,1,4,-5,4};
        int max = findMax(a);
        System.out.println(max);
    }

    public static int findMax(int[] array){
        int max = array[0];
        int result = max;
        for (int i = 1; i < array.length; i++) {
            if (max <=0 && array[i]>max){
                max = array[i];
            }
            else if (max>0){
                max+=array[i];
            }
            if (max > result){
                result = max;
            }
        }
        return result;
    }

}
